<template>
  <div>
    <el-dialog :visible.sync="dialogOpen" title="确认库存并提交订单" center top="50px" width="60%">
      <ProductInput
          api="newOrderOutMaterials"
          :params="{ id: comfirmId }"
          v-model="arr"
      />
      <span slot="footer">
         <el-button @click="dialogOpen = false">取 消</el-button>
        <el-button type="primary" v-preventReClick @click="onConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import ProductInput from "../components/ProductInput.vue";

export default {
  name: "comfirmOrder",
  components: {
    ProductInput,
  },
  data() {
    return {
      dialogOpen: false,
      comfirmId: "",
      arr: []
    }
  },
  methods: {
    handleOpen(val) {
      this.comfirmId = val.id
      this.dialogOpen = true
    },
    onConfirm() {
      let data = {}
      this.$message({message: "正在确认库存，请耐心等候！", type: "warning"})
      const materials = this.arr
          .filter((e) => e.id && e.count)
          .map((e) => {
            return {id: e.id, count: e.count, norms: e.norms, productCode: e.productCode};
          });
      if (!materials.length) return this.$message.error("请完善产品输入");
      data.id = this.comfirmId;
      data.orderId = this.comfirmId
      data.status = 0;
      // data.outMaterialsList = materials;
      this.$api.orderConfirmOrderSenior(data).then(res => {
        if (res == 505) {
          this.$message({message: "产品库存不足，无法确认订单，已发送短信给仓库主管!", type: "warning"})
        } else {
          data = {}
          this.dialogOpen = false
          this.$emit('addStatus', 1)
        }
      });
    },
  }
}
</script>

<style scoped lang="less">
/deep/ .el-dialog__header {
  background-color: #0f79e2;
  //border-top-left-radius: 20px;
  //border-top-right-radius: 20px;
}

/deep/ .el-dialog__title {
  color: #fff;
}

</style>